class Scheduler {
    constructor(limit) {
        this.tasks = [];
        this.cur = []
        this.limit = limit;

    }
    add(fn) {
        return new Promise(resolve => {
            this.tasks.push([fn,resolve])
            if(this.cur > this.limit) {
                this.run()
            }
        })
    }

    run() {
        this.cur ++ 
        let [task,resolve] = this.tasks.shift()
        Promise.resolve(() => {
            task()

        }).then(()=> {
            resolve()
            this.curr -- 
            this.run()
        })
    }

}

function maxArrSum(arr) {
    let dp = new Array({length:arr.length})
    let max = nums[0]
    for (let i = 0; i < arr.length; i++) {
        dp[i] = Math.max(dp[i],dp[i]+ arr[i])
        if (max < dp[i]) {
            max = dp[i];
        }
    }
    return max
}


function orderLevel(root) {
    const ret = [];
    if(!root) {
        return ret
    }
    let queue = [root]
    
    while(queue.length !== 0 ) {
        const currLevelSize = queue.length
        ret.push([]);
        for(let i = 0; i < currLevelSize;i ++) {
            res
        }
    }

}

function myNew(func) {
    let newObj = {
        __proto__: func.prototype,
    }
    func.apply(newObj,arguments)
    return newObj
}

function instanceof(target,source) {
    while(target) {
        if(target.__proto__ === source.prototype) {
            return true
        }
        target = target.__proto__
    }
    return false
 }